<?php

include_once($GLOBALS['cfgPaths']['lib'].'model2/ValidationErrors.o.inc.php');
include_once($GLOBALS['cfgPaths']['lib'].'model2/ActionForm.o.inc.php');
include_once($GLOBALS['MODEL2_BASEDIR'].'model/OrderModel.o.inc.php');
include_once($GLOBALS['cfgPaths']['lib/dba'].'dbaOrder.o.inc.php');
include_once($GLOBALS['MODEL2_BASEDIR'].'langres/login_res.inc.php');
include_once($GLOBALS['cfgPaths']['etcPath'].'var_main.inc.php');

class OrderPasswordRetrievalAction extends WebAction
{
    
    function execute($env)
    {
        $dbao = new dbaOrder($GLOBALS['udba']);
        $af = new ActionForm();
        if ($env->param('email') 
            && $pwd = $dbao->findPasswordByEmail($env->param('email')))
        {
            mail($env->param('email'), $GLOBALS['cfgXICSShop']['retrieval_subject'][$GLOBALS['lang_name']], 
                sprintf($GLOBALS['cfgXICSShop']['retrieval_email'][$GLOBALS['lang_name']] ,$pwd));
            $this->copyResources($af, 'pwd_retr', array('headline', 'email', 'send_button', 'sent_text'));
            $this->forward('order/passwordRetrievedView', $af);
        }
        else
        {
            $this->copyResources($af, 'pwd_retr', array('headline', 'email', 'send_button', 'sent_text'));
            $this->forward('order/passwordRetrievalFormView', $af);
        }
    }

}

?>